package com.library.common.net

import com.library.common.ext.mmkv
import com.library.common.util.MMKVContancts
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException
import kotlin.jvm.Throws

/**
 * 自定义头部参数拦截器，传入heads
 */
class HeadInterceptor : Interceptor {
    companion object{
        var sessionId = ""
    }
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        if(sessionId.isEmpty()){
            sessionId = mmkv.decodeString(
                MMKVContancts.SESSIONID, "")
        }
        val builder = chain.request().newBuilder()
        builder.addHeader("Access-Token",
            sessionId
        ).build()
        builder.addHeader("device", "Android").build()
        return chain.proceed(builder.build())
    }

}